package com.tyrone.gateway.transport;

import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.*;

/**
 * @author yelong.xie
 * @date 2024/5/8 23:34
 */
public class InvokeUtils {
    static HttpRequest convertToHttpRequest(Invoke invoke) {
        HttpRequest request = new DefaultFullHttpRequest(
                HttpVersion.HTTP_1_1, HttpMethod.GET, invoke.getRawPath(), Unpooled.EMPTY_BUFFER);
        request.headers().set(HttpHeaderNames.HOST, invoke.getHost());
        request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
        request.headers().set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);

//                    // Set some example cookies.
//                    request.headers().set(
//                            HttpHeaderNames.COOKIE,
//                            io.netty.handler.codec.http.cookie.ClientCookieEncoder.STRICT.encode(
//                                    new io.netty.handler.codec.http.cookie.DefaultCookie("my-cookie", "foo"),
//                                    new DefaultCookie("another-cookie", "bar")));

        // Send the HTTP request.
        return request;
    }
}
